﻿@model AesApplication.Models.ApplyViewModel

@using AesApplication.Models;

@{
    ViewBag.Title = "Apply";
}

<h2>Apply for @Model.Job.Title at @Model.Job.Department.Store.Name</h2>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
    
    <fieldset>
        <div class="editor-label">
            @Html.LabelFor(model => model.Application.FirstName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Application.FirstName)
            @Html.ValidationMessageFor(model => model.Application.FirstName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Application.LastName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Application.LastName)
            @Html.ValidationMessageFor(model => model.Application.LastName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Application.BirthDate)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Application.BirthDate)
            @Html.ValidationMessageFor(model => model.Application.BirthDate)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Application.Address)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Application.Address)
            @Html.ValidationMessageFor(model => model.Application.Address)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Application.City)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Application.City)
            @Html.ValidationMessageFor(model => model.Application.City)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Application.State)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Application.State)
            @Html.ValidationMessageFor(model => model.Application.State)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Application.Zip)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Application.Zip)
            @Html.ValidationMessageFor(model => model.Application.Zip)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Application.WorkHistory)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Application.WorkHistory)
            @Html.ValidationMessageFor(model => model.Application.WorkHistory)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Application.Education)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Application.Education)
            @Html.ValidationMessageFor(model => model.Application.Education)
        </div>

        @if (Model.Job.Questionnaire != null)
        {
            <h4>Questionnaire</h4>

            for (int i = 0; i < Model.Questions.Count(); ++i)
            {
                Question question = Model.Questions[i];
                
                <p>@question.Number. @question.GetDisplayText()</p>
            
                if (question.Type == QuestionType.Essay)
                {
                    @Html.TextAreaFor(model => model.Answers[i].Text)
                }
                else if (question.Type == QuestionType.MultipleChoice)
                {
                    <ul>
                    @foreach (Question.MultipleChoiceOption option in question.GetMultipleChoiceOptions())
                    {
                        <li>
                            @Html.RadioButtonFor(model => model.Answers[i].Text, option.Name)
                            @option.Text
                        </li>
                    }
                    </ul>
                }
                else
                {
                    @Html.EditorFor(model => model.Answers[i].Text)
                }
            }
            
        }

        <p>
            <input type="submit" value="Submit" />
        </p>
    </fieldset>
}